package me.zk;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @Author: zhang kai
 * @Date: 2022/07/07
 * @Description:
 */
public class PredicateDemo {
    public static void main(String[] args) {
        List<Apple> apples = Arrays.asList(new Apple(80,"green"), new Apple(120,"green"),new Apple(32,"red"));
        List<Apple> result = filter(apples,apple -> apple.weight > 50);
        System.out.println(result);
    }

    static List<Apple> filter(List<Apple> apples, Predicate<Apple> p) {
        return apples.stream().filter(p).collect(Collectors.toList());
    }

}
class Apple {
    int weight;
    String color;
    Apple(){}
    Apple(int weight, String color) {
        this.color = color;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "weight=" + weight +
                ", color='" + color + '\'' +
                '}';
    }
}